package Object类;
//public StringtoString to String()  返回对象的字符串表示形式。建议所有子类重写方法，自动生成
//public boolean equals(Object obj)  比较对象是否相等，默认比较地址，重写可以比较内容，自动生成

import java.util.Objects;

public class Student extends Object{
    private String name;
    private int age;

    public Student(){}
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        //this --- s1
        //obj --- s2 地址值
        //比较地址是否相同，相同返回true
        if (this == o) return true;

        //参数是否为null,null则false
        //getClass拿的是字节码文件，判断是否来自同一类
        if (o == null || getClass() != o.getClass()) return false;

        //向下转型
        Student student = (Student) o;//student =s2;

        //比较s1和s2的年龄是否相同
        if (age != student.age) return false;

        //比较姓名是否相同
        return Objects.equals(name, student.name);

    }

   /* @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + age;
        return result;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }*/
}

